//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Collections.Generic;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel;
using EntLibContrib.Query.Parameters;

namespace EntLibContrib.Query.Configuration
{
    using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Design;

    /// <summary>
	/// Type to hold the elements of a single query parameter
	/// </summary>
    [ResourceDescription(typeof(DesignResources), "XmlParameterDataDescription")]
    [ResourceDisplayName(typeof(DesignResources), "XmlParameterDataDisplayName")]
	public class XmlParameterData : ParameterData
	{
		#region Fields
		private const string namespaceProperty = "namespace";
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the type of the parameter.
		/// </summary>
		/// <value>The type of the parameter.</value>
		[ConfigurationProperty(namespaceProperty, IsRequired = false)]
        [ResourceDescription(typeof(DesignResources), "XmlParameterDataNamespaceDescription")]
        [ResourceDisplayName(typeof(DesignResources), "XmlParameterDataNamespaceDisplayName")]
		public string Namespace
		{
			get { return (string)base[namespaceProperty]; }
			set { base[namespaceProperty] = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="XmlParameterData"/> class.
		/// </summary>
		public XmlParameterData()
            : base(null, typeof(XmlParameter))
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="XmlParameterData"/> class.
		/// </summary>
		/// <param name="name">The parameter name.</param>
		/// <param name="namespaceName">Name of the namespace.</param>
		public XmlParameterData(string name, string namespaceName)
			: base(name, typeof(XmlParameter))
		{
			this.Namespace = namespaceName;
		}
		#endregion

		/// <summary>
		/// A <see cref="TypeRegistration"/> container configuration model for <see cref="XmlParameterData"/>.
		/// </summary>
        /// <param name="name">The name to use for the child elements.</param>
		/// <returns>A <see cref="TypeRegistration"/> for registering a <see cref="XmlParameterData"/> in the container.</returns>
		public override IEnumerable<TypeRegistration> GetRegistrations(string name)
		{
			yield return
				new TypeRegistration<IParameter>(
					() => new XmlParameter(Name, Namespace))
				{
                    Lifetime = TypeRegistrationLifetime.Transient,
                    Name = name,
                    IsPublicName = false
                };
		}
	}
}
